define(["jquery", "easy-admin"], function ($, ea) {

    var init = {
        table_elem: '#currentTable',
        table_render_id: 'currentTableRenderId',
        index_url: 'dealer.order_indent/index',
        add_url: 'dealer.order_indent/add',
        edit_url: 'dealer.order_indent/edit',
        delete_url: 'dealer.order_indent/delete',
        export_url: 'dealer.order_indent/export',
        modify_url: 'dealer.order_indent/modify',
        refund_url: 'dealer.order/refund',
    };

    return {
        index: function () {
            ea.table.render({
                init: init,
                toolbar: ['refresh'],
                // toolbar: ['refresh',
                //     [{
                //         text: '添加',
                //         url: init.add_url,
                //         method: 'open',
                //         auth: 'add',
                //         class: 'layui-btn layui-btn-normal layui-btn-sm',
                //         icon: 'fa fa-plus ',
                //         extend: 'data-full="true"',
                //     }],
                //     'delete', 'export'],
                cols: [[
                    {field: 'order_sn', title: '订单编号' ,width:160},
                    {field: 'total_amount', title: '总金额', minWidth: 120 ,search:'false'
                    ,templet: function(d){
                        if (d.total_amount == null) {
                            return'￥0.00';
                        } else {
                            return '￥'+d.total_amount;
                        }
                    }},
                    {field: 'goods_num', title: '实发商品', minWidth: 100 ,search:'false',templet: function(d){
                        return d.goods_name+' *'+(d.goods_num+d.gift_num);
                    }},
                    {field: 'goods_num', title: '商品信息', minWidth: 200 ,search:'false',templet: function(d){
                        if (d.gift_num > 0) {
                            return' 商品:'+d.goods_num+' 赠品:'+d.gift_num;
                        } else {
                            return' 商品:'+d.goods_num;
                        }
                    }},
                    {field: 'order_name', title: '收货人' ,hide: true},
                    {field: 'order_phone', title: '手机号' ,hide: true},
                    {field: 'order_address',title: '订单信息' ,minWidth:300 ,search:'false' ,templet: function(d){
                        return d.order_name+' '+d.order_phone+' '+d.province+''+d.city+''+d.area+''+d.order_address;
                    }},
                    {field: 'refund_status',title: '退款状态' ,minWidth:100 ,search: 'select', selectList: {0: '未退款', 1: '已退款'},templet: function(d){
                        if (d.refund_status == 1) {
                            return'已退款';
                        } else {
                            return '未退款';
                        }
                    }},
                    {field: 'remark', Width: 100, title: '备注', search: 'false'},
                    {field: 'create_time', minWidth: 160, title: '创建时间', search: 'range'},
                    {
                        fixed: 'right',
                        width: 200,
                        title: '操作',
                        templet: function(e){
                                // 物流
                                // var l ='<a class="layui-btn layuimini-btn-success layui-btn-xs" data-open="supplier.order/logistics_list?order_id='+e.id+'" data-title="订单物流信息" data-full="false">物流信息</a>'
                                var l ='<a class="layui-btn layuimini-btn-normal layui-btn-xs" data-url="dealer.OrderIndent/indentUpdate?order_id='+e.id+'" data-title="确定订购转为待发货订单？" data-id="'+e.id+'" data-table-indent>转为待发货</a>'
                                // var l ='';
                                // 退款
                                if (e.refund_status==1 || e.logistics_status>0) {
                                    l +=''; 
                                } else {
                                    l +=' <a class="layui-btn layuimini-btn-normal layui-btn-xs" data-url="'+init.refund_url+'" data-title="确定退款？" data-id="'+e.id+'" data-table-refund>退款</a>'
                                }
                                return l;  
                            }
                    },
                ]],
            });
            ea.listen();
        },
        add: function () {
            ea.listen();
        },
        edit: function () {
            ea.listen();
        },
    };
});